<?php
/**
 * Basic class for handling alert messages
 *
 * @package adroit
 */
class AdroitAlertHandler {

    public static $TYPE_ERROR = 'typeError';
    public static $TYPE_SUCCESS = 'typeSuccess';
    public static $SESSION_KEY = 'adroitAlerts';
    
    /**
     * @var Array String array of alert messages
     */
   public $alerts = Array();
   
   /**
    * Constructor
    *
    * @return AdroitAlertHandler
    */
   public function AdroitAlertHandler() {
      
   }
   
   /**
    * Adds an alert to the collection.
    * 
    * @param String $message
    * @param String $type
    * @param String $id (optional) defaults to null
    */
   public function addAlert($message, $type, $id=null) {
       $alert = new AdroitAlert($message, $type, $id);
       if(@$this->alerts[$type] == null) {
           $this->alerts[$type] = Array();
       }
       $this->alerts[$type][] = $alert;
   }
   
   /**
    * Check for existing alerts
    *
    * @return boolean
    */
   function alertsExist($type) {
      if(count($this->alerts[$type]) > 0 ) {
          return true;
      }else {
          return false;
      }
   }
   
}

/**
 * Single alert object
 * 
 * @package adroit
 */
class AdroitAlert {
    
    /**
     * @var String Actual message to display for alert
     */
    public $message;
    
    /**
     * @var String Id for mapping alert to a specific attribute
     */
    public $id;
    
    /**
     * Constructor
     *
     * @param String $message
     * @param String $type
     * @param String $id
     * @return AdroitAlert
     */
    public function AdroitAlert($message, $type, $id) {
        $this->message = $message;
        $this->type = $type;
        $this->id = $id;
    }
    
}
?>